/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.telsoft.managedbean.function;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.faces.context.FacesContext;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletResponse;

/**
 *
 * @author THANHBINH
 */
@ManagedBean(name = "func_download")
@ViewScoped
public class Func_Download {

    private String downloadFile;
    private LeftProcessBean leftProcess;

    public Func_Download() {
        FacesContext context = FacesContext.getCurrentInstance();
        leftProcess = (LeftProcessBean) context.getApplication().evaluateExpressionGet(context, "#{treeNode}", LeftProcessBean.class);
        ServletContext context2 = (ServletContext) FacesContext.getCurrentInstance().getExternalContext().getContext();
        HttpServletResponse response = (HttpServletResponse) FacesContext.getCurrentInstance().getExternalContext().getResponse();
        response.setContentType("application/force-download");
//      downloadFile=leftProcess.getLib().get(0).getLibID();
        response.addHeader("Content-Disposition", "attachment; filename=\"" + downloadFile + "\"");
        byte[] buf = new byte[1024];
        try {
            String realPath = downloadFile;
        } catch (Exception exc) {
            String str = exc.toString();
        }
    }

    public String getDownloadFile() {
        return downloadFile;
    }

    public void setDownloadFile(String downloadFile) {
        this.downloadFile = downloadFile;
    }
}
